<?php

class conection {
    
    public static $host = "127.0.0.1";
    public static $usuario = "root";
    public static $contrasena = "admin";
    public static $bdd = "a9167819_fragand";
    /*public static $host = "mysql8.000webhost.com";
    public static $usuario = "a9167819_tienda";
    public static $contrasena = "eljotoma1";
    public static $bdd = "a9167819_fragand";*/
    public static $conection;
    public static $femenino = 1;
    public static $masculino = 2;
    public static $citricos = 1;
    public static $floral = 2;
    public static $fougere = 3;
    public static $chypre = 4;
    public static $madera = 5;
    public static $orientalAmbar = 6;
    public static $losCuero = 7;
    public static $genero;
    public static $tipo;
    public static $tabla;
    public static $indxId = 0;
    public static $indxNombre = 1;
    public static $indxPrecio = 2;
    public static $indxContenido = 3;
    public static $indxImagen = 4;
    public static $indxGenero = 5;
    public static $indxTipo = 6;
    
    public static function make() {

        $result = false;

        self::$conection = mysql_connect(self::$host, self::$usuario, self::$contrasena); 

        if (!self::$conection) {
            echo "No se pudo establecer la Conecci&oacute;n a la Base de Dato! Servidor, Usuario y/o Contrase&ntilde;a Incorrecto.";
        }else{
            $conection_DB = mysql_select_db(self::$bdd);
            if(!$conection_DB){
                echo "No se pudo establecer la Conecci&oacute;n a la Base de Datos!";
            } else {
                $result = true;
            }
        }
        
        return $result;
    }
    
    public static function close() {
        mysql_close(self::$conection);
    }
    
    public static function insert($sql) {
        
        self::$conection = mysql_connect(self::$host, self::$usuario, self::$contrasena); 
        
        $result = false;

        if (!self::$conection) {
            echo "No se pudo establecer la Conecci&oacute;n a la Base de Dato! Servidor, Usuario y/o Contrase&ntilde;a Incorrecto.";
        }else{
            $conection_DB = mysql_select_db(self::$bdd);
            if(!$conection_DB){
                echo "No se pudo establecer la Conecci&oacute;n a la Base de Datos!";
            } else {
                var_dump($sql);
                $var = mysql_query($sql, self::$conection);
                if($var){
                    $result = true;
                }
            }
        }
        return $result;
    }


    public static function login($user, $password) {
        self::$conection = mysql_connect(self::$host, self::$usuario, self::$contrasena); 
        
        $result = false;
        
        $password = md5($password);

        if (!self::$conection) {
            echo "No se pudo establecer la Conecci&oacute;n a la Base de Dato! Servidor, Usuario y/o Contrase&ntilde;a Incorrecto.";
        }else{
            $conection_DB = mysql_select_db(self::$bdd);
            if(!$conection_DB){
                echo "No se pudo establecer la Conecci&oacute;n a la Base de Datos!";
            } else {
                $consulta = mysql_query("SELECT * FROM users WHERE username='$user' AND password='$password'");
                if(mysql_num_rows($consulta) == 1){
                    while ($row = mysql_fetch_array($consulta, MYSQL_NUM)) {
                        $_SESSION["user"] = $row[3];
                    }
                    $result = true;
                }
            }
        }
        return $result;
    }
}
?>
